// const ccc = { name: "宫保鸡丁", price: 10 };
const dataSource = [
  { name: "宫保鸡丁", price: 10 },
  { name: "麻辣烫", price: 10 },
  { name: "鱼香肉丝", price: 11 },
  { name: "酸辣土豆丝", price: 9 },
  { name: "红烧肉", price: 15 },
  { name: "麻辣鸭血", price: 13 },
  { name: "麻辣香锅", price: 14 },
  { name: "干锅牛蛙", price: 18 },
  { name: "酸菜鱼", price: 16 },
  { name: "回锅肉", price: 12 },
];

// find 会返回满足条件的第一项
const findResult = dataSource.find(function (item, index, array) {
  //   console.log(item.price);
  return item.price === 10;
  //   console.log(item, index, array);
});
// console.log(result);

// 会以数组的形式返回满足条件的所有项目，
const filterResult = dataSource.filter(function (item, index, array) {
  //   console.log(item.price);
  return item.price === 100;
  //   console.log(item, index, array);
});

// 会返回是否包含，一定要注意是值类型，还是引用类型
// console.log(filterResult);
const a = [1, 2, 3, 4];
const includesResult = a.includes(2);
// const includesResult = dataSource.includes(ccc);
// console.log(includesResult);

// map会将返回的数据，重新组合成一个数组
const mapResult = dataSource.map(function (item, index, array) {
  item.price = item.price + 1;
  return item;
});

// 不会返回数据，只会对数组进行遍历
const forEachResult = dataSource.forEach(function (item, index, array) {
  console.log(item);
  item.price = item.price + 1;
  return item;
});
// console.log(forEachResult);
// console.log(dataSource);

// 如果数组中有一个满足条件，则返回true
const someResult = dataSource.some(function (item, index, array) {
  return item.price === 20;
});

const everyResult = dataSource.every(function (item, index, array) {
  return item.price > 15;
});

console.log(everyResult);
